local current = tonumber(redis.call('GET', KEYS[1]) or 0)

if current >= tonumber(ARGV[1]) then
    return 0
end

redis.call('INCR', KEYS[1])

if current == 0 then
    local now = redis.call('TIME')

    -- 考虑时区偏移，这样定死时区是否合理？
    local timezoneOffset = 8 * 3600

    local secondsSinceMidnight = (tonumber(now[1]) + timezoneOffset) % 86400
    local secondsUntilMidnight = 86400 - secondsSinceMidnight

    redis.call('EXPIRE', KEYS[1], secondsUntilMidnight)
end

return 1